package com.fingerth.crawler.room

import androidx.room.*


@Dao
interface NovelChapterDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(chapter: NovelChapter)

//    @Insert(onConflict = OnConflictStrategy.REPLACE)
//    fun insert(vararg chapter: NovelChapter)

    @Update
    fun update(vararg chapter: NovelChapter)

    @Delete
    fun delete(vararg chapter: NovelChapter)

    //删除所有
    @Query("DELETE FROM NovelChapter ")
    fun deleteAll()

    @Query("DELETE FROM NovelChapter WHERE fictionId == :fid")
    fun deleteByFictionId(fid: String)

    @Query("SELECT COUNT(*) FROM NovelChapter ")
    fun count(): Int

    @Query("SELECT COUNT(*) FROM NovelChapter WHERE  fictionId == :fid")
    fun countByFictionId(fid: String): Int


    @Query("SELECT * FROM NovelChapter LIMIT :size OFFSET :index")
    fun query(index: Int, size: Int): Array<NovelChapter>

    @Query("SELECT * FROM NovelChapter ORDER BY id DESC LIMIT 1 OFFSET :index ")
    fun queryByIndex(index: Int): NovelChapter


    @Query("SELECT * FROM NovelChapter WHERE chapterId == :id")
    fun queryById(id: String): NovelChapter?

    @Query("SELECT * FROM NovelChapter WHERE  fictionId == :fictionId ORDER BY cid")
    fun queryByFictionId(fictionId: String): Array<NovelChapter>

    @Query("SELECT * FROM NovelChapter WHERE  fictionId == :fictionId ORDER BY cid  LIMIT :pageSize OFFSET :offset")
    fun queryByFictionId(fictionId: String, offset: Int, pageSize: Int): Array<NovelChapter>

}